package com.team.frame.utils.alidayu;

import com.taobao.api.ApiException;
import com.taobao.api.Constants;
import com.taobao.api.TaobaoClient;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.domain.BizResult;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import com.team.frame.utils.Tools;

/**
 * Created by lidan on 2017/1/20.
 * 此类是阿里云通信的封装类
 * API地址：https://api.alidayu.com/docs/api.htm?spm=a3142.7395905.4.6.L3cEqn&apiId=25450
 */
public class AliDaYu {

    //短信平台信息
    public static final String SM_SERVER_URL="http://gw.api.taobao.com/router/rest";
    public static final String SM_SERVER_APPKEY="23581016";
    public static final String SM_SERVER_APPSECRET="aca5039be8af3521fa4817749f841216";

    /**
     * 短信发送（阿里大于）
     * @param phone 手机号
     * @param content 短信内容
     * @param template 短信模板
     * @param singName 短信签名
     * @return
     * @author lidan
     */
    public static boolean sendCode(String phone, String content, String template, String singName) {
        TaobaoClient client = new DefaultTaobaoClient(SM_SERVER_URL, SM_SERVER_APPKEY, SM_SERVER_APPSECRET);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        //req.setExtend("123456");
        req.setSmsType("normal");
        req.setSmsFreeSignName(singName); //短信签名
        //req.setSmsParamString("{\"code\":\"1234\",\"name\":\"测试\"}");
        req.setSmsParamString(content);
        req.setRecNum(phone);
        req.setSmsTemplateCode(template); //短信模板 SMS_18265235
        try{
            AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
            System.out.println(rsp.getBody());
            BizResult bizResult = rsp.getResult();
            if (null != bizResult) {
                return bizResult.getSuccess();
            } else {
                return false;
            }
        }catch(ApiException e){
            e.printStackTrace();
            return false;

        }
    }




}
